import { http } from '@/utils/http'
import type { queryParams } from '@/types/order'
import type {
  OrderPreResult,
  OrderCreateParams,
  OrderDetailParams,
  OrderLogistics,
  OrderItem,
} from '@/types/order'

// 填写订单 - 获取预付订单
// GET / member / order / pre
export const getMemberOrderPreAPI = () => {
  return http<OrderPreResult>({
    method: 'GET',
    url: '/member/order/pre',
  })
}

// 填写订单 - 获取立即购买订单
// GET / member / order / pre / now
export const getMemberOrderPreNowAPI = (data: {
  skuId: string
  count: string
  addressId?: string
}) => {
  return http<OrderPreResult>({
    method: 'GET',
    url: '/member/order/pre/now',
    data,
  })
}

// 提交订单
// POST/member/order
export const postMemberOrderAPI = (data: OrderCreateParams) => {
  return http<{ id: string }>({
    method: 'POST',
    url: '/member/order',
    data,
  })
}

// 获取订单详情
// GET/member/order/{id}
export const getMemberOrderByIdAPI = (id: string) => {
  return http<OrderDetailParams>({
    method: 'GET',
    url: `/member/order/${id}`,
  })
}

// 再次购买
// /member/order / repurchase / { id }
export const getMemberOrderRepurchaseByIdAPI = (id: string) => {
  return http<OrderPreResult>({
    method: 'GET',
    url: `/member/order/repurchase/${id}`,
  })
}

// 获取订单物流
// GET / member / order / { id } / logistics
export const getMemberOrderLogisticsByIdAPI = (id: string) => {
  return http<OrderLogistics>({
    method: 'GET',
    url: `/member/order/${id}/logistics`,
  })
}

// 取消订单
// PUT/member/order/{id}/cancel
export const putMemberOrderCancelByIdAPI = (id: string, data: { cancelReason: string }) => {
  return http({
    method: 'PUT',
    url: `/member/order/${id}/cancel`,
    data,
  })
}

// 删除订单
// DELETE/member/order
export const deleteMemberOrderAPI = (data: { ids: string[] }) => {
  return http({
    method: 'DELETE',
    url: '/member/order',
    data,
  })
}
//获取订单列表
// /member/order
export const getMemberOrderAPI = (data: queryParams) => {
  return http<OrderItem>({
    method: 'GET',
    url: '/member/order',
    data,
  })
}
